package com.exercise.cn.config;

import com.alibaba.druid.support.spring.stat.DruidStatInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.JdkRegexpMethodPointcut;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Scope;

/**
 * @author admin
 * 2019/12/3-17:37
 **/
@Configuration
@EnableAspectJAutoProxy
public class DruidAspectConfig {
    @Bean
    public DruidStatInterceptor druidStatInterceptor(){
        return new DruidStatInterceptor();
    }
    @Bean
    @Scope("prototype")
    public JdkRegexpMethodPointcut druidStatPointcut (){
        JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();;
        pointcut.setPatterns("com.exercise.cn.mapper.*","com.exercise.cn.service.*");
        return pointcut;
    }
    @Bean
    public DefaultPointcutAdvisor druidPointcutAdvisor(DruidStatInterceptor druidStatInterceptor,
                                                       JdkRegexpMethodPointcut druidStatPointcut                                               ){
        DefaultPointcutAdvisor druidPointcutAdvisor =new DefaultPointcutAdvisor();
        druidPointcutAdvisor.setPointcut(druidStatPointcut);
        druidPointcutAdvisor.setAdvice(druidStatInterceptor);
        return druidPointcutAdvisor;
    }
}

